]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
portalHelper: Use private data/cache directories
authorBastien Nocera <hadess@hadess.net>
Mon, 23 Jan 2017 06:14:17 +0000 (07:14 +0100)
committerBastien Nocera <hadess@hadess.net>
Tue, 24 Jan 2017 12:36:09 +0000 (13:36 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=775639

js/portalHelper/main.js

index 39846420edab74b8941ef31b31de897c682dfac3..367659de3fece2ef83165a9949d4934f263f0960 100644 (file)
@@ -12,6 +12,7 @@ const WebKit = imports.gi.WebKit2;
 const _ = Gettext.gettext;
 
 const Config = imports.misc.config;
+const FileUtils = imports.misc.fileUtils;
 
 const PortalHelperResult = {
     CANCELLED: 0,
@@ -50,6 +51,7 @@ const PortalWindow = new Lang.Class({
 
     _init: function(application, url, timestamp, doneCallback) {
         this.parent({ application: application });
+        this.connect('delete-event', Lang.bind(this, this.destroyWindow));
 
         if (!url) {
             url = CONNECTIVITY_CHECK_URI;
@@ -63,8 +65,15 @@ const PortalWindow = new Lang.Class({
         this._doneCallback = doneCallback;
         this._lastRecheck = 0;
         this._recheckAtExit = false;
+        let cacheDir = GLib.Dir.make_tmp("gnome-shell-portal-helper-XXXXXXXX");
+        this._cacheDir = Gio.File.new_for_path(cacheDir);
 
-        this._webView = new WebKit.WebView();
+        let dataManager = new WebKit.WebsiteDataManager({ base_data_directory: cacheDir,
+                                                          base_cache_directory: cacheDir });
+        let webContext = new WebKit.WebContext({ website_data_manager: dataManager });
+        webContext.set_cache_model(WebKit.CacheModel.DOCUMENT_VIEWER);
+
+        this._webView = WebKit.WebView.new_with_context(webContext);
         this._webView.connect('decide-policy', Lang.bind(this, this._onDecidePolicy));
         this._webView.load_uri(url);
         this._webView.connect('notify::title', Lang.bind(this, this._syncTitle));
@@ -78,6 +87,11 @@ const PortalWindow = new Lang.Class({
         this.application.set_accels_for_action('app.quit', ['<Primary>q', '<Primary>w']);
     },
 
+    destroyWindow: function() {
+        this.destroy();
+        FileUtils.recursivelyDeleteDir(this._cacheDir, true);
+    },
+
     _syncTitle: function() {
         let title = this._webView.title;
 
@@ -172,7 +186,7 @@ const WebPortalHelper = new Lang.Class({
         this._queue = [];
 
         let action = new Gio.SimpleAction({ name: 'quit' });
-        action.connect('activate', () => { this.active_window.destroy(); });
+        action.connect('activate', () => { this.active_window.destroyWindow(); });
         this.add_action(action);
     },
 
@@ -205,7 +219,7 @@ const WebPortalHelper = new Lang.Class({
 
             if (obj.connection == connection) {
                 if (obj.window)
-                    obj.window.destroy();
+                    obj.window.destroyWindow();
                 this._queue.splice(i, 1);
                 break;
             }